package proxy;

/**
 * Created by : Infaraway
 * DATE : 2017/3/3
 * Time : 19:51
 * Funtion : java静态代理类实现
 */
public class StaticProxy implements Calculator {

    private CalculatorImpl calculatorImpl;

    public StaticProxy(CalculatorImpl calculatorImpl){
        this.calculatorImpl = calculatorImpl;
    }

    @Override
    public int add(int a, int b) {
        System.out.println("the add method begin...");
        //调用被代理类的方法
        int result = calculatorImpl.add(a, b);
        System.out.println("the add method end...");
        return result;
    }

    @Override
    public int sub(int a, int b) {
        System.out.println("the sub method begin...");
        //调用被代理类的方法
        int result = calculatorImpl.sub(a, b);
        System.out.println("the sub method end...");
        return result;
    }

    @Override
    public void mul(int a, int b) {
        System.out.println("the mul method begin...");
        //调用被代理类的方法
        calculatorImpl.mul(a, b);
        System.out.println("the mul method end...");

    }

    @Override
    public void div(int a, int b) {
        System.out.println("the div method begin...");
        //调用被代理类的方法
        calculatorImpl.div(a, b);
        System.out.println("the div method end...");
    }
}
